<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
  <th:block th:include="include :: header('项目列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
  <div class="row">
    <div class="col-sm-12 search-collapse">
      <form id="formId">
        <div class="select-list">
          <ul>
            <li>
              项目名称：<input type="text" name="projectName"/>
            </li>
            <li>
              项目进度：
              <select name="progressCode" th:with="type=${@dict.getType('project_progress')}">
                <option value="">--所有--</option>
                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
              </select>
            </li>
            <li>
              污水类型：
              <select name="sewageType" th:with="type=${@dict.getType('sewage_type')}">
                <option value="">--所有--</option>
                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
              </select>
            </li>
            <li>
              <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
              <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
            </li>
          </ul>
        </div>
      </form>
    </div>

    <div class="btn-group-sm" id="toolbar" role="group">
      <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="project:projectInfo:add">
        <i class="fa fa-plus"></i> 添加
      </a>
      <a class="btn btn-primary btn-edit disabled" onclick="$.operate.editTab()"
         shiro:hasPermission="project:projectInfo:edit">
        <i class="fa fa-edit"></i> 完善信息
      </a>
      <a class="btn btn-danger btn-del disabled" onclick="$.operate.removeAll()"
         shiro:hasPermission="project:projectInfo:remove">
        <i class="fa fa-remove"></i> 删除
      </a>
    </div>
    <div class="col-sm-12 select-table table-striped">
      <table id="bootstrap-table" data-mobile-responsive="true"></table>
    </div>
  </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
  var editFlag = [[${@permission.hasPermi('project:projectInfo:edit')}]];
  var removeFlag = [[${@permission.hasPermi('project:projectInfo:remove')}]];
  var sewageDatas = [[${@dict.getType('sewage_type')}]];
  var progressDatas = [[${@dict.getType('project_progress')}]];
  var prefix = ctx + "project/projectInfo";

  $(function () {
    var options = {
      url: prefix + "/list",
      createUrl: prefix + "/add",
      updateUrl: prefix + "/edit/{id}",
      removeUrl: prefix + "/remove",
      modalName: "项目信息",
      columns: [{
        checkbox: true
      },
        {
          field: 'projectId',
          title: '项目ID',
          visible: false
        },
        {
          field: 'projectName',
          title: '项目名称'
        },
        {
          field: 'progressCode',
          title: '项目进度',
          formatter: function (value, row, index) {
            return $.table.selectDictLabel(progressDatas, value);
          }
        },
        {
          field: 'sewageType',
          title: '污水类型',
          formatter: function (value, row, index) {
            return $.table.selectDictLabel(sewageDatas, value);
          }
        },
        {
          field: 'designIntake',
          title: '设计进水量(t/d)'
        },
        {
          field: 'actualIntake',
          title: '实际进水量(t/d)'
        },
        {
          field: 'projectPrice',
          title: '项目金额(元)'
        },
        {
          field: 'techPrice',
          title: '技术服务费(元)'
        },
        {
          field: 'createBy',
          title: '创建者'
        },
        {
          field: 'createTime',
          title: '创建时间'
        },
        {
          title: '操作',
          align: 'center',
          formatter: function (value, row, index) {
            var actions = [];
            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.projectId + '\')">完善信息</a> ');
            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="projectInfoVisible(\'' + row.projectId + '\')">数据可见</a> ');
            if (row.progressCode == '1' || row.progressCode == '2' || row.progressCode == '3' || row.progressCode == '4') {
              actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="projectPartner(\'' + row.projectId + '\')">参与人员</a> ');
              actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="viewProjectProgress(\'' + row.projectId + '\')">项目进度</a> ');
              actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.projectId + '\')">删除</a>');
            }
            if (row.progressCode == '5') {
              actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="projectPay(\'' + row.projectId + '\')">付款</a> ');
            }
            if (row.progressCode == '6') {
              actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="projectGuide(\'' + row.projectId + '\')">现场指导</a> ');
            }
            return actions.join('');
          }
        }]
    };
    $.table.init(options);
  });

  function viewProjectProgress(projectId) {
    var url = prefix + '/progress/' + projectId;
    $.modal.openTab("项目进度", url);
  }

  function projectPartner(projectId) {
    var url = prefix + '/partner/' + projectId;
    $.modal.open("项目参与人员", url);
  }

  function projectInfoVisible(projectId) {
    var url = prefix + '/visible/' + projectId;
    $.modal.open("数据可见", url);
  }

  function projectPay(projectId) {
    $.modal.confirm("确认要设置该项目进度为“付款”吗？", function() {
      $.operate.post(prefix + "/pay", { "projectId": projectId, "progressCode": 6});
    });
  }

  function projectGuide(projectId) {
    $.modal.confirm("确认要设置该项目进度为“现场指导”吗？", function() {
      $.operate.post(prefix + "/guide", { "projectId": projectId, "progressCode": 7});
    });
  }
</script>
</body>
</html>